package com.ruoyi.community.wxconfig;


import com.ruoyi.community.interceptor.ThirdSessionInterceptor;
import com.ruoyi.community.service.IUserService;
import lombok.AllArgsConstructor;
import org.springframework.context.annotation.Configuration;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;

/**
 * web配置
 */
@Configuration
@AllArgsConstructor
public class WebConfig implements WebMvcConfigurer {
	private IUserService userService;
	private final RedisTemplate redisTemplate;

	/**
	 * 拦截器
	 * @param registry
	 */
	@Override
	public void addInterceptors(InterceptorRegistry registry) {
		/**
		 * 进入ThirdSession拦截器
		 * 注册拦截器
		 */
		registry.addInterceptor(new ThirdSessionInterceptor(userService,redisTemplate))
				.addPathPatterns("/wx/mp/**")//拦截/api/**接口
				.excludePathPatterns("/wx/mp/oauth2/geturl",
						"/wx/mp/login");//放行接口
	}
}
